
import axios from "axios";

const baseUrl = "http://192.169.3.10:9814/"
const baseUrlLocal = "http://192.169.3.104:8080/"

const apiGet = axios.create({
    baseURL: baseUrl,
    timeout: 10000,
});
const apiPost = axios.create({
    baseURL: baseUrl,
    timeout: 10000,
    headers: {
        // 后端普遍接收form-data,如果不配置，默认发送的是json，会收不到
        'Content-Type': 'multipart/form-data',
    },
});

export const fetchData = async (url: string) => {
    try {
        const response = await apiGet.get(url);
        return response.data.data;
    } catch (error) {
        console.error(`Error fetching data from ${url}:`, error);
        throw error;
    }
};

export const postDataAdmin = async (url: string,data: any) => {
    try {
        // 设置 Authorization 头部
        apiPost.defaults.headers.common['Authorization'] = `6667ad12c97c0815460764da`;

        const response = await apiPost.post(url,data);
        return response.data.data;
    } catch (error) {
        console.error(`Error fetching data from ${url}:`, error);
        throw error;
    }
};